package com.itheima.config;

import com.itheima.interceptor.LoginInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 注册拦截器
 */
//@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {

    //配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //创建自定义拦截对象
        LoginInterceptor interceptor = new LoginInterceptor();
        //配置白名单
        List<String> patterns = new ArrayList<>();
        patterns.add("/backend/api/**");
        patterns.add("/backend/images/**");
        patterns.add("/backend/js/**");
        patterns.add("/backend/plugins/**");
        patterns.add("/backend/styles/**");
        patterns.add("/backend/favicon.ico");
        patterns.add("/backend/page/login/login.html");
        patterns.add("/employee/login");
        //完成拦截器的注册
        registry.addInterceptor(interceptor).addPathPatterns("/**")  //表示拦截所有
                .excludePathPatterns(patterns); //除了以下资源和路径
    }
}
